package cn.hloger.spider.demo.dataxDemo; /**
 * TODO
 *
 * @Description TODO
 * @author huanglong
 * @data 2024/7/15
 */

import cn.hutool.core.util.CharsetUtil;
import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.util.List;

/**
 * datax运行需要两个
 * 一个是  打包好的(或者直接下载的datax运行文件) /bin/datax.py
 * 还有一个是datax的配置文件 job.json
 *
 * @author long
 * @version 1.0
 * @description: TODO
 * @date 2024/7/15 16:33
 */
public class CommentRunner {
    public static void main(String[] args) {
        // Path to DataX home
        String dataXHome = "/path/to/datax";
        // Path to the JSON job file
        String jobFilePath = "/path/to/job.json";

        // Construct the command to execute DataX
        String command = "ipconfig";

        try {
            // Execute the command
            Process process = Runtime.getRuntime().exec(command);

//            List<String> strings = IOUtils.readLines(process.getInputStream(), CharsetUtil.CHARSET_UTF_8);
            List<String> strings = IOUtils.readLines(process.getInputStream(), CharsetUtil.CHARSET_GBK);
            strings.forEach(System.out::println);
            int exitCode = process.waitFor();
            if (exitCode == 0) {
                System.out.println("DataX job executed successfully.");
            } else {
                System.err.println("DataX job failed with exit code " + exitCode);
            }
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}
